<template>
  <div>
    <el-button @click="add()" type="primary">新增产品</el-button>
    <el-table :data="tableList">
      <el-table-column prop="id" align="center" label="ID"></el-table-column>
      <el-table-column prop="name" align="center" label="产品名称"></el-table-column>
      <el-table-column prop="createTime" align="center" label="创建日期"></el-table-column>
      <el-table-column prop="updateTime" align="center" label="修改日期"></el-table-column>
      <el-table-column label="操作" align="center" width="220">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row.id)" type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
const queryString = require("querystring");
import page from "data/page";
import { typeList } from "data/listBody";
export default {
  mixins: [page],
  data() {
    return {
      tableList: [],
      currentPage: 1,
      pageShow: false,
      typeList
    };
  },
  created() {
    this.search();
  },
  methods: {
    search() {
      const params = {
        page: this.currentPage - 1,
        size: 20
      };
      this.axios
        .get("/product?" + queryString.stringify(params))
        .then(res => {
          const code = Number(res.data.code);
          if (code === 200) {
            this.tableList = res.data.data;
            this.tableList.forEach((comInfo, index) => {
              this.tableList[index].ipoValue = comInfo.ipo ? "是" : "否";
              this.tableList[index].createTime = this.timeFormater(
                comInfo.createTime
              ).format("YYYY-MM-DD");
              this.tableList[index].updateTime = this.timeFormater(
                comInfo.updateTime
              ).format("YYYY-MM-DD");
            });
            this.setPage(res.data.data);
          } else {
            this.$message(this.mes.busy);
          }
        })
        .catch(err => {
          console.log(err);
          this.$message(this.mes.busy);
        });
    },
    add() {
      this.$router.push("productMain?type=add");
    },
    edit(id) {
      this.$router.push("productMain?type=edit&id=" + id);
    }
  }
};
</script>
<style lang="less" scoped>
</style>
